var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";
async function connect(){
    let db =  await MongoClient.connect(url,{useNewUrlParser:true});
    return db
}
async function token(dbc,collection,query){
    let db = await dbc();
    let dbo = db.db('mongo');
    var where = query;
    var promise = dbo.collection(collection).findOne(where)
    return promise
}


async function token2user(dbc){
    let db = await dbc();
    let dbo = db.db('mongo');
    let toke = await token(dbc,'token',{token:"bad5892094893550d65f61c74e44cef6"});
    let ref = toke.userinfo;
    console.log(ref)
}
token2user(connect)
module.exports =  token